package com.tts.repository;

import com.tts.entity.Book;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Optional;

@Repository
public interface BookRepository extends JpaRepository<Book, Long> {
    Optional<Book> findByIsbn(String isbn);
    
    boolean existsByIsbn(String isbn);
    
    List<Book> findByNameContainingOrAuthorContaining(String name, String author);
    
    @Query("SELECT b FROM Book b WHERE b.stock > 0 AND b.status = 'AVAILABLE'")
    List<Book> findAvailableBooks();
    
    List<Book> findByCategory(String category);
} 